package com.lt.phone;

import android.os.Build;
import android.os.Environment;
import android.os.StatFs;

import java.io.File;

/**
 * 设备的一些相关信息
 * Created by tianlan on 2018/1/9.
 */

public class DeviceDetail {

    public DeviceDetail() {
    }

    /**
     * @return 系统总空间
     */
    public long getExternalTotalSize() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            File sdcardDir = Environment.getExternalStorageDirectory();
            StatFs sf = new StatFs(sdcardDir.getPath());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                return sf.getBlockSizeLong() * sf.getBlockCountLong();
            } else {
                return sf.getBlockSize() * sf.getBlockCount();
            }
        }
        return 0;
    }

    /**
     * @return 外部可用空间
     */
    public long getExternalAvailableSize() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            File sdcardDir = Environment.getExternalStorageDirectory();
            StatFs sf = new StatFs(sdcardDir.getPath());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                return sf.getBlockSizeLong() * sf.getBlockCountLong();
            } else {
                return sf.getBlockSize() * sf.getBlockCount();
            }
        }
        return 0;
    }

    /**
     * @return 系统总空间
     */
    public long getSysTotalSize() {
        File root = Environment.getDataDirectory();
        StatFs sf = new StatFs(root.getPath());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return sf.getBlockSizeLong() * sf.getBlockCountLong();
        } else {
            return sf.getBlockSize() * sf.getBlockCount();
        }
    }


    /**
     * @return 系统可用空间
     */
    public long getSysAvailableSize() {
        File root = Environment.getDataDirectory();
        StatFs sf = new StatFs(root.getPath());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return sf.getBlockSizeLong() * sf.getBlockCountLong();
        } else {
            return sf.getBlockSize() * sf.getBlockCount();
        }
    }
}
